<template>
  <div class="ma-content-block lg:flex justify-between p-4">
    <!-- CRUD 组件 -->
    <ma-crud :options="options" :columns="columns" ref="crudRef">
    </ma-crud>
  </div>
</template>
<script setup>
import { ref, reactive } from 'vue'
import appsApplication from '@/api/apps/appsApplication'
import { Message } from '@arco-design/web-vue'
import tool from '@/utils/tool'
import * as common from '@/utils/common'

const crudRef = ref()


const numberOperation = (newValue, id, numberName) => {
  appsApplication.numberOperation({ id, numberName, numberValue: newValue }).then( res => {
    res.success && Message.success(res.message)
  }).catch( e => { console.log(e) } )
}

const switchStatus = (statusValue, id, statusName) => {
  appsApplication.changeStatus({ id, statusName, statusValue }).then( res => {
    res.success && Message.success(res.message)
  }).catch( e => { console.log(e) } )
}


const options = reactive({
  id: 'apps_application',
  rowSelection: {
    showCheckedAll: true
  },
  pk: 'id',
  operationColumn: true,
  operationWidth: 160,
  formOption: {
    viewType: 'modal',
    width: 600
  },
  api: appsApplication.getList,
  recycleApi: appsApplication.getRecycleList,
  add: {
    show: true,
    api: appsApplication.save,
    auth: ['apps:application:save']
  },
  edit: {
    show: true,
    api: appsApplication.update,
    auth: ['apps:application:update']
  },
  delete: {
    show: true,
    api: appsApplication.deletes,
    auth: ['apps:application:delete'],
    realApi: appsApplication.realDeletes,
    realAuth: ['apps:application:realDeletes']
  },
  recovery: {
    show: true,
    api: appsApplication.recoverys,
    auth: ['apps:application:recovery']
  }
})

const columns = reactive([
  {
    title: "主键",
    dataIndex: "id",
    formType: "input",
    addDisplay: false,
    editDisplay: false,
    hide: true,
    commonRules: {
      required: true,
      message: "请输入主键"
    }
  },
  {
    title: "创建者",
    dataIndex: "created_by",
    formType: "input",
    addDisplay: false,
    editDisplay: false,
    hide: true
  },
  {
    title: "更新者",
    dataIndex: "updated_by",
    formType: "input",
    addDisplay: false,
    editDisplay: false,
    hide: true
  },
  {
    title: "创建时间",
    dataIndex: "created_at",
    formType: "date",
    addDisplay: false,
    editDisplay: false,
    hide: true,
    showTime: true
  },
  {
    title: "更新时间",
    dataIndex: "updated_at",
    formType: "date",
    addDisplay: false,
    editDisplay: false,
    hide: true,
    showTime: true
  },
  {
    title: "删除时间",
    dataIndex: "deleted_at",
    formType: "date",
    addDisplay: false,
    editDisplay: false,
    hide: true,
    showTime: true
  },
  {
    title: "备注",
    dataIndex: "remark",
    formType: "input",
    addDisplay: false,
    editDisplay: false,
    hide: true
  },
  {
    title: "应用名称",
    dataIndex: "name",
    formType: "input",
    search: true,
    commonRules: {
      required: true,
      message: "请输入应用名称"
    }
  },
  {
    title: "应用标识",
    dataIndex: "code",
    formType: "input",
    search: true,
    commonRules: {
      required: true,
      message: "请输入应用标识"
    }
  },
  {
    title: "应用密钥",
    dataIndex: "secret",
    formType: "input",
    search: true,
    hide: true,
    commonRules: {
      required: true,
      message: "请输入应用密钥"
    }
  },
  {
    title: "应用ID",
    dataIndex: "appid",
    formType: "input",
    search: true,
    hide: true,
    commonRules: {
      required: true,
      message: "请输入应用ID"
    }
  },
  {
    title: "收藏页图",
    dataIndex: "collection_banner",
    formType: "upload",
    commonRules: {
      required: true,
      message: "请输入收藏页图"
    }
  },
  {
    title: "头部logo",
    dataIndex: "header_image",
    formType: "upload",
    commonRules: {
      required: true,
      message: "请输入头部logo"
    },
    type: "image",
    multiple: false
  },
  {
    title: "激活头部logo",
    dataIndex: "header_image_active",
    formType: "upload",
    commonRules: {
      required: true,
      message: "请输入头部logo"
    },
    type: "image",
    multiple: false
  }
])
</script>
<script> export default { name: 'apps:application' } </script>